package com.glc.gao.gavin.rxjavademo.operator;

import android.view.View;

import com.glc.gao.gavin.rxjavademo.R;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.ObservableSource;
import io.reactivex.functions.Consumer;

public class ConcatActivity extends BaseActivity {
    @Override
    public int getDescribeText() {
        return R.string.describe_concat;
    }

    @Override
    protected int getContextView() {
        return R.layout.activity_concat;
    }

    public void executeConcat(View view) {
        Observable.concat(Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(ObservableEmitter<Integer> e) throws Exception {
                print("111");
                e.onNext(111);
                print("222");
                e.onNext(222);
                print("333");
                e.onNext(333);
                e.onComplete();
            }

        }), Observable.create(new ObservableOnSubscribe<Integer>() {
            @Override
            public void subscribe(ObservableEmitter<Integer> e) throws Exception {
                print("444");
                e.onNext(444);
                print("555");
                e.onNext(555);
                print("666");
                e.onNext(666);

            }
        })).subscribe(new Consumer<Integer>() {
            @Override
            public void accept(Integer integer) throws Exception {
                print("accept" + integer);
            }
        });
    }
}
